﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC_Tutorial.Filters;
using MVC_Tutorial.Models;

namespace MVC_Tutorial.Controllers
{
   [InitializeSimpleMembership]
    public class HomeController : Controller
    {
        private Author author = new BlogModelContainer().Authors.ToArray<Author>()[0];
        private BlogModelContainer db = new BlogModelContainer();

        public ActionResult Index()
        {
            ViewBag.Message = "My Blog's Motto";
            IEnumerable<BlogPost> posts = db.BlogPosts.ToList();
            posts = posts.Reverse();
            
            return View(posts);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View(author);
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View(author);
        }

        public ActionResult Post(int id)
        {
            BlogPost blogpost = db.BlogPosts.Find(id);
            if (blogpost == null)
            {
                return HttpNotFound();
            }
            return View(blogpost);
        }
    }
}
